-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Ref #1589: Add warning messages for migration annotation #3562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ref #1589: Add warning messages for migration annotation #3562
Conversation
…sion. RefCheck:698
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Added" instead of "Add")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
Please change the commit message to |
…d-changed-semantics-in-version # Conflicts: # compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java # compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
val explanation = | ||
hl"""$migrationMessage | ||
| | ||
|The symbol is marked with ${"@migration"} indicating it has changed semantics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not talk about symbols as this is a compiler internal concept, the user should not know about them. You should probably replace it with ${symbol.showLocated}
or ${symbol.show}
.
| | ||
|The symbol is marked with ${"@migration"} indicating it has changed semantics | ||
|between versions and the ${"-Xmigration"} settings is used to warn about constructs | ||
|whose behavior may have changed since version.""".stripMargin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"may have changed since version" -> "may have changed since version change"
val explanation = { | ||
hl"""The symbol is marked with ${"@migration"} indicating it has changed semantics | ||
|between versions and the ${"-Xmigration"} settings is used to warn about constructs | ||
|whose behavior may have changed since version.""".stripMargin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
hl"""${symbol.showLocated} has changed semantics in version $symbolVersion: | ||
|$migrationVersion""".stripMargin | ||
val explanation = { | ||
hl"""The symbol is marked with ${"@migration"} indicating it has changed semantics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same (symbol)
I was always curious about this annotation. Is there any reason why it is not part of the standard library? ATM, it is available only internally Just out of curiosity, Swift provides the In Swift,
In scala's ecosystem, this would mean the possibility to achieve something like: PS: Not a suggestion, just toughts ;) |
false | ||
} | ||
if (changed) | ||
ctx.warning(s"${sym.showLocated} has changed semantics in version $symVersion:\n${sym.migrationMessage.get}") | ||
ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're at it. Can you move this into the match. There is no need for this changed
variable.
Also, symVersion
is sym.migrationVersion.get
so you don't need both of them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. 1sec.
ctx.settings.Xmigration.value < v | ||
val xMigrationValue = ctx.settings.Xmigration.value | ||
if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) { | ||
sym.migrationVersion.get match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your match is not exhaustive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) { | ||
sym.migrationVersion.get match { | ||
case scala.util.Success(symVersion) if xMigrationValue < symVersion => | ||
ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove sym.migrationMessage.get
. It is the same as symVersion
. I don't know why it was duplicated in the first place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have to change the final message if that is ok. Currently:
${symbol.showLocated} has changed semantics in version $symbolVersion:
$migrationVersion
The migrationMessage provides either a version string or an error message from ScalaVersion.parse
:
def failure = Failure(new NumberFormatException(
s"There was a problem parsing ${versionString}. " +
"Versions should be in the form major[.minor[.revision]] " +
"where each part is a positive number, as in 2.10.1. " +
"The minor and revision parts are optional."
))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It cannot be a failure since you're in the Success
case of the match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) { | ||
sym.migrationVersion.get match { | ||
case scala.util.Success(symVersion) if xMigrationValue < symVersion => | ||
ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing the pos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| | ||
|The ${symbol.showLocated} is marked with ${"@migration"} indicating it has changed semantics | ||
|between versions and the ${"-Xmigration"} settings is used to warn about constructs | ||
|whose behavior may have changed since version change.""".stripMargin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to stripMargin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
val explanation = { | ||
hl"""The ${symbol.showLocated} is marked with ${"@migration"} indicating it has changed semantics | ||
|between versions and the ${"-Xmigration"} settings is used to warn about constructs | ||
|whose behavior may have changed since version change.""".stripMargin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to stripMargin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to update your submodules:
git submodule update
ctx.warning(s"${sym.showLocated} has an unparsable version number: ${ex.getMessage()}", pos) | ||
false | ||
ctx.warning(SymbolHasUnparsableVersionNumber(sym, ex.getMessage()), pos) | ||
case _ => () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove ()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
…d-changed-semantics-in-version
Regarding #1589, this PR addresses: